home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12851 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: thales.nmia.com!not-for-mail
  2. From: ghealton@nmia.com (Gilbert Healton)
  3. Newsgroups: comp.lang.c++
  4. Subject: \\ question fo iostream people //
  5. Date: 22 Mar 1996 00:57:57 GMT
  6. Organization: New Mexico Internet Access
  7. Message-ID: <4istul$jon@thales.nmia.com>
  8. NNTP-Posting-Host: socrates.nmia.com
  9. X-Newsreader: TIN [UNIX 1.3 950515BETA PL0]
  10.  
  11. How many good ways are there to solve this problem (I am looking for one):
  12.  
  13.    Set up some type of I/O stream (or stream reference and stream) that
  14.    allows a program to write to either standard out or a selected file.
  15.    The ability to switch at will at different points of the program is 
  16.    vital. Code that works on different compilers is preferred.
  17.  
  18. In C the code is simple and portable:
  19.  
  20.     FILE  *Stream = (FILE *)NULL;
  21.     char  *StreamPath;
  22.      . . .
  23.     if ( SomeCondition )
  24.     {   // time to open a file
  25.         if ( Stream )        //but, first, if already open
  26.             fclose( Stream );    ////close the puppy
  27.         if ( *StreamPath )        
  28.         Stream = fopen( StreamPath, "w" ); // disk file
  29.         else
  30.         Stream = stdout;           // stdout
  31.     }
  32.  
  33. If I get some good answers, I'll put them in FAQ format and forward them
  34. to the C++ FAQ.
  35.  
  36. -- 
  37. ----- Computer Consulting / Web Pages -----    http://www.nmia.com/~ghealton/
  38. These opinions are my own. Life is learning and I may retract, modify, 
  39. even attack, my previous ideas at any time without notice.
  40.